package com.hotau.phonegap.plugin;

import org.apache.cordova.api.Plugin;
import org.apache.cordova.api.PluginResult;
import org.json.JSONArray;

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.util.Log;

import com.hotau.HotauActivity;
import com.hotau.product.ProductDetailFragment;
import com.hotau.product.vo.Product;

public class FragmentLinkPlugin extends Plugin {

	private final static String TAG = "FragmentLinkPlugin";

	@Override
	public PluginResult execute(String action, JSONArray data, String callbackId) {
		Log.d(TAG, "Hello, this is a native function called from PhoneGap/Cordova!");
		HotauActivity.INSTANCE.runOnUiThread(new Runnable() {
			
			@Override
			public void run() {
				Fragment fragment = new ProductDetailFragment();
				
				Bundle bundle = new Bundle();
				bundle.putSerializable("product", new Product("3", "口水鸡", null, 30, 0, 10, 3, null));
				fragment.setArguments(bundle);

				HotauActivity.INSTANCE.pushFragment("", fragment);
			}
		});
		
		return null;
	}

}
